﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Is point within a circle</title>
    <link href="styles/js-console.css" rel="stylesheet" />
    <script src="scripts/isValidInput.js"></script>
</head>
<body>
    <label for="xCoord">Enter x coord:</label>
    <input type="text" id="xCoord" />
    <label for="yCoord">Enter y coord:</label>
    <input type="text" id="yCoord" />
    <button onclick="IsPointInCircle()">Is point in circle K(0,5)</button>
    <div id="js-console"></div>
    <script src="scripts/js-console.js"></script>
    <script>
        //Write an expression that checks if given print (x,  y) is within a circle K(O, 5).
        function IsPointInCircle() {
            var circleXCoord = 0;
            var circleYCoord = 0;
            var circleRadius = 5;
            var xCoord = parseFloat(document.getElementById("xCoord").value);
            var yCoord = parseFloat(document.getElementById("yCoord").value);
            if (isValidInputNumber(xCoord) && isValidInputNumber(yCoord)) {
                if (Math.sqrt(
                    (xCoord - circleXCoord) * (xCoord - circleXCoord) +
                    (yCoord - circleYCoord) * (yCoord - circleYCoord)) <= circleRadius) {
                    jsConsole.writeLine("The point is in the circle.")
                }
                else {
                    jsConsole.writeLine("The point is NOT in the circle.");
                }
            }
            else {
                jsConsole.writeLine("Enter valid numbers.")
            }
        }
    </script>
</body>
</html>
